<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        
        <meta name="author" content="隐星魂 (Roy.Sun)">
        
        <link rel="shortcut icon" href="../../../img/favicon.ico">
        <title>开发环境搭建指南 - 玄武操作系统</title>
        <link href="../../../css/bootstrap.min.css" rel="stylesheet">
        <link href="../../../css/font-awesome.min.css" rel="stylesheet">
        <link href="../../../css/base.css" rel="stylesheet">
        <link rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.3/styles/color-brewer.min.css">

        <script src="../../../js/jquery-1.10.2.min.js" defer></script>
        <script src="../../../js/bootstrap.min.js" defer></script>
        <script src="https://cdn.staticfile.org/highlight.js/10.0.3/highlight.min.js"></script>
        <script>hljs.initHighlightingOnLoad();</script> 
    </head>

    <body>
        <div class="navbar fixed-top navbar-expand-lg navbar-dark bg-primary">
            <div class="container">
                <a class="navbar-brand" href="../../..">玄武操作系统</a>
                <!-- Expander button -->
                <button type="button" class="navbar-toggler" data-toggle="collapse" data-target="#navbar-collapse">
                    <span class="navbar-toggler-icon"></span>
                </button>

                <!-- Expanded navigation -->
                <div id="navbar-collapse" class="navbar-collapse collapse">
                        <!-- Main navigation -->
                        <ul class="nav navbar-nav">
                            <li class="navitem">
                                <a href="../../.." class="nav-link">主页</a>
                            </li>
                            <li class="navitem">
                                <a href="../../../license/" class="nav-link">开源协议</a>
                            </li>
                            <li class="dropdown active">
                                <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">快速开发指南 <b class="caret"></b></a>
                                <ul class="dropdown-menu">
                                    
  <li class="dropdown-submenu">
    <a href="#" class="dropdown-item">STM32</a>
    <ul class="dropdown-menu">
            
<li>
    <a href="./" class="dropdown-item active">开发环境搭建指南</a>
</li>
            
<li>
    <a href="../02-Project-Setup-Guide/" class="dropdown-item">工程配置指南</a>
</li>
            
<li>
    <a href="../03-atkh743/" class="dropdown-item">正点原子阿波罗H743开发板上手指南</a>
</li>
            
<li>
    <a href="../04-fk429m/" class="dropdown-item">反客F429核心板上手指南</a>
</li>
            
<li>
    <a href="../05-atkf407core/" class="dropdown-item">正点原子F407核心板上手指南</a>
</li>
            
<li>
    <a href="../06-atkf103core/" class="dropdown-item">正点原子F103核心板上手指南</a>
</li>
    </ul>
  </li>
                                    
  <li class="dropdown-submenu">
    <a href="#" class="dropdown-item">NXP S32K</a>
    <ul class="dropdown-menu">
            
<li>
    <a href="../../s32k/01-Envsetup-Guide/" class="dropdown-item">开发环境搭建指南</a>
</li>
            
<li>
    <a href="../../s32k/02-Project-Setup-Guide/" class="dropdown-item">工程配置指南</a>
</li>
    </ul>
  </li>
                                    
  <li class="dropdown-submenu">
    <a href="#" class="dropdown-item">玄武内核模块</a>
    <ul class="dropdown-menu">
            
<li>
    <a href="../../xwko/01-XuanWuKO-Guide/" class="dropdown-item">上手指南</a>
</li>
    </ul>
  </li>
                                </ul>
                            </li>
                            <li class="dropdown">
                                <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">应用手册 <b class="caret"></b></a>
                                <ul class="dropdown-menu">
                                    
<li>
    <a href="../../../UserManual/00-index/" class="dropdown-item">00.目录</a>
</li>
                                    
<li>
    <a href="../../../UserManual/01-brief/" class="dropdown-item">01.简介</a>
</li>
                                    
<li>
    <a href="../../../UserManual/02-Basic-System-Architecture/" class="dropdown-item">02.系统基本架构</a>
</li>
                                    
<li>
    <a href="../../../UserManual/03-Build-System/" class="dropdown-item">03.构建系统</a>
</li>
                                    
<li>
    <a href="../../../UserManual/04-Boot-Flow/" class="dropdown-item">04.启动流程</a>
</li>
                                    
<li>
    <a href="../../../UserManual/05-IRQ/" class="dropdown-item">05.中断控制</a>
</li>
                                    
<li>
    <a href="../../../UserManual/06-SKD/" class="dropdown-item">06.调度器</a>
</li>
                                    
<li>
    <a href="../../../UserManual/07-Thread/" class="dropdown-item">07.线程</a>
</li>
                                    
<li>
    <a href="../../../UserManual/08-SWT/" class="dropdown-item">08.软件定时器</a>
</li>
                                    
<li>
    <a href="../../../UserManual/09-PM/" class="dropdown-item">09.电源管理</a>
</li>
                                    
<li>
    <a href="../../../UserManual/10-Lock/" class="dropdown-item">10.锁</a>
</li>
                                    
<li>
    <a href="../../../UserManual/11-Sync/" class="dropdown-item">11.同步</a>
</li>
                                    
<li>
    <a href="../../../UserManual/12-MM/" class="dropdown-item">12.内存管理</a>
</li>
                                    
<li>
    <a href="../../../UserManual/13-C-Lib/" class="dropdown-item">13.玄武C库</a>
</li>
                                </ul>
                            </li>
                            <li class="dropdown">
                                <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">移植笔记 <b class="caret"></b></a>
                                <ul class="dropdown-menu">
                                    
<li>
    <a href="../../../PortingNote/00-index/" class="dropdown-item">目录</a>
</li>
                                    
<li>
    <a href="../../../PortingNote/01-Porting-Note/" class="dropdown-item">移植笔记</a>
</li>
                                    
  <li class="dropdown-submenu">
    <a href="#" class="dropdown-item">ARM-Cortex-M</a>
    <ul class="dropdown-menu">
            
<li>
    <a href="../../../PortingNote/ARM-Cortex-M/01-ARM-Cortex-M-Porting-Note/" class="dropdown-item">架构移植笔记</a>
</li>
            
<li>
    <a href="../../../PortingNote/ARM-Cortex-M/02-STM32-Porting-Note/" class="dropdown-item">STM32</a>
</li>
    </ul>
  </li>
                                </ul>
                            </li>
                            <li class="dropdown">
                                <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">规范 <b class="caret"></b></a>
                                <ul class="dropdown-menu">
                                    
<li>
    <a href="../../../Specification/00-index/" class="dropdown-item">目录</a>
</li>
                                    
<li>
    <a href="../../../Specification/01-Git-Commit-Specification/" class="dropdown-item">git-commit规范</a>
</li>
                                    
<li>
    <a href="../../../Specification/02-Version-Branch-Specification/" class="dropdown-item">版本分支规范</a>
</li>
                                </ul>
                            </li>
                        </ul>

                    <ul class="nav navbar-nav ml-auto">
                        <li class="nav-item">
                            <a href="#" class="nav-link" data-toggle="modal" data-target="#mkdocs_search_modal">
                                <i class="fa fa-search"></i> 搜索
                            </a>
                        </li>
                            <li class="nav-item">
                                <a rel="prev" href="../../../license/" class="nav-link">
                                    <i class="fa fa-arrow-left"></i> 上一篇
                                </a>
                            </li>
                            <li class="nav-item">
                                <a rel="next" href="../02-Project-Setup-Guide/" class="nav-link">
                                    下一篇 <i class="fa fa-arrow-right"></i>
                                </a>
                            </li>
                    </ul>
                </div>
            </div>
        </div>

        <div class="container">
            <div class="row">
                    <div class="col-md-3"><div class="navbar-light navbar-expand-md bs-sidebar hidden-print affix" role="complementary">
    <div class="navbar-header">
        <button type="button" class="navbar-toggler collapsed" data-toggle="collapse" data-target="#toc-collapse" title="Table of Contents">
            <span class="fa fa-angle-down"></span>
        </button>
    </div>

    
    <div id="toc-collapse" class="navbar-collapse collapse card bg-secondary">
        <ul class="nav flex-column">
            
            <li class="nav-item" data-level="1"><a href="#_1" class="nav-link">开发环境搭建指南</a>
              <ul class="nav flex-column">
              </ul>
            </li>
            
            <li class="nav-item" data-level="1"><a href="#1ubuntu-64bit" class="nav-link">1.ubuntu-64bit</a>
              <ul class="nav flex-column">
            <li class="nav-item" data-level="2"><a href="#11" class="nav-link">1.1.基本工具</a>
              <ul class="nav flex-column">
              </ul>
            </li>
            <li class="nav-item" data-level="2"><a href="#12stm32cubeide" class="nav-link">1.2.STM32CubeIDE</a>
              <ul class="nav flex-column">
              </ul>
            </li>
            <li class="nav-item" data-level="2"><a href="#13stm32cubemx" class="nav-link">1.3.STM32CubeMX</a>
              <ul class="nav flex-column">
              </ul>
            </li>
              </ul>
            </li>
            
            <li class="nav-item" data-level="1"><a href="#2windows-10-64bit" class="nav-link">2.Windows-10-64bit</a>
              <ul class="nav flex-column">
            <li class="nav-item" data-level="2"><a href="#21" class="nav-link">2.1.基本工具</a>
              <ul class="nav flex-column">
              </ul>
            </li>
            <li class="nav-item" data-level="2"><a href="#22stm32cubeide" class="nav-link">2.2.STM32CubeIDE</a>
              <ul class="nav flex-column">
              </ul>
            </li>
            <li class="nav-item" data-level="2"><a href="#23stm32cubemx" class="nav-link">2.3.STM32CubeMX</a>
              <ul class="nav flex-column">
              </ul>
            </li>
              </ul>
            </li>
            
            <li class="nav-item" data-level="1"><a href="#_4" class="nav-link">附录</a>
              <ul class="nav flex-column">
              </ul>
            </li>
        </ul>
    </div>
</div></div>
                    <div class="col-md-9" role="main">

<h1 id="_1">开发环境搭建指南</h1>
<hr />
<h1 id="1ubuntu-64bit">1.ubuntu-64bit</h1>
<h2 id="11">1.1.基本工具</h2>
<h4 id="bash">bash</h4>
<ul>
<li>设置bash为默认的shell：</li>
</ul>
<pre><code class="sh">sudo dpkg-reconfigure dash # 选择“否”
</code></pre>

<h4 id="make">make</h4>
<ul>
<li>安装方法</li>
</ul>
<pre><code class="sh">sudo apt install build-essential
</code></pre>

<h4 id="jdk">jdk</h4>
<ul>
<li>用途：运行IDE中各种工具；</li>
<li>可选openjdk-11或openjdk-8，安装方法：</li>
</ul>
<pre><code class="sh">sudo apt install openjdk-8-jdk
</code></pre>

<ul>
<li>也可选oracle的jdk，STM32CubeProgrammer只能在Oracle-jdk-8下运行。可到官方网站
    <a href="https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html">https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html</a>
    下载，下载完成后需要将其安装目录放在环境变量<strong>PATH</strong>中。可在<strong>/etc/profiled.d/</strong>
    目录下建立一个新文件<strong>java.sh</strong>，并写入下面内容：</li>
</ul>
<pre><code class="sh">export JAVA_HOME=&quot;OracleJDK的安装目录&quot;
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${PATH}:${JAVA_HOME}/bin
</code></pre>

<h4 id="emacs">emacs</h4>
<ul>
<li>用途：执行elisp脚本；</li>
<li>安装方法</li>
</ul>
<pre><code class="sh">sudo apt-add-repository ppa:kelleyk/emacs
sudo apt-get update
sudo apt install emacs27
</code></pre>

<h4 id="gcc">gcc工具链</h4>
<p>为了方便读者，已打包好的工具链可从网盘下载：</p>
<ul>
<li><a href="https://pan.baidu.com/s/1WwSaEajt6JqgMOLOa8iPEQ">https://pan.baidu.com/s/1WwSaEajt6JqgMOLOa8iPEQ</a></li>
<li>提取码：xwos</li>
<li>文件：gnumcu-linux.tar.xz</li>
<li>解压命令：</li>
</ul>
<pre><code class="sh">sudo tar xvfJp gnumcu-linux.tar.xz -C /opt/ # 注意带上选项p，否则解压后脚本可能丢失执行权限
</code></pre>

<p>解压到安装路径<strong>/opt/</strong>：</p>
<pre><code class="sh">/opt
└─ gnumcu
     ├── arm-none-eabi
     ├── bin
     ├── include
     ├── lib
     ├── lib64
     ├── libexec
     ├── scripts
     └── share
</code></pre>

<ul>
<li>将<strong>/opt/gnumcu/bin</strong>增加到环境变量Path中</li>
</ul>
<pre><code class="sh">sudo sh -c &quot;echo 'export PATH=\${PATH}:/opt/gnumcu/bin' &gt; \
            /etc/profile.d/gnumcu.sh&quot;
sudo chmod +x /etc/profile.d/gnumcu.sh
</code></pre>

<p>设置完成后，需要注销后，重新登录才可生效。可通过下面的命令测试工具链：</p>
<pre><code class="sh">arm-none-eabi-gcc -v
openocd -v
</code></pre>

<p>工具链来源于<a href="https://gnu-mcu-eclipse.github.io/downloads/">GNU MCU Eclipse</a>，
其中gcc又来源于<a href="https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm">ARM官方</a>，
若有更新的版本，可下载：</p>
<ul>
<li><a href="https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/">xPack GNU Arm Embedded GCC</a></li>
<li><a href="https://github.com/xpack-dev-tools/openocd-xpack/releases/">xPack OpenOCD</a></li>
</ul>
<hr />
<h2 id="12stm32cubeide">1.2.STM32CubeIDE</h2>
<ul>
<li>优点：有一个强大的SFR插件，可以在调试时很方便查看外设寄存器的值；</li>
<li>缺点：不支持DAPLink调试器，不过可以安装OpenOCD插件支持。</li>
</ul>
<h4 id="ide">安装IDE</h4>
<ul>
<li>从<a href="https://www.st.com/content/st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-ides/stm32cubeide.html">STM32CubeIDE官网</a>下载；</li>
<li>Ubuntu系统可以下载STM32CubeIDE-DEB进行安装；</li>
<li>下载完成后应该是一个很大的shell脚本，需要增加执行权限后使用sudo进行安装；</li>
<li>安装过程中，需要接受许可证，许可证比较长，可以按'q'键跳过。</li>
</ul>
<pre><code class="sh">chmod +x st-stm32cubeide_1.3.0_5720_20200220_1053_amd64.deb_bundle.sh
sudo ./st-stm32cubeide_1.3.0_5720_20200220_1053_amd64.deb_bundle.sh
</code></pre>

<hr />
<h4 id="openocd">安装OpenOCD插件</h4>
<ul>
<li>打开菜单"Help &#x2013;&gt; Install New Software&#x2026;"；</li>
<li>点击"Add&#x2026;"，增加下面的仓库；</li>
</ul>
<pre><code class="sh">Name: Eclipse Embedded CDT Plug-ins
URL: https://download.eclipse.org/embed-cdt/updates/neon/
</code></pre>

<ul>
<li>等待刷新，选择安装<ul>
<li>"<strong>C/C++ OpenOCD Debugging</strong>"插件；</li>
<li>"<strong>C/C++ J-Link Debugging</strong>"插件；</li>
</ul>
</li>
</ul>
<hr />
<h2 id="13stm32cubemx">1.3.STM32CubeMX</h2>
<ul>
<li>
<p>下载STM32CubeMx的安装包，网站链接：<a href="https://www.st.com/en/development-tools/stm32cubemx.html">STM32CubeMX</a></p>
</li>
<li>
<p>解压后找到Linux环境的安装包 <strong>SetupSTM32CubeMX-x.y.z.linux</strong> ，右键点击此
    文件，在属性中选中 <strong>“允许作为程序执行文件”</strong> 即可增加执行权限，双击运行
    按照提示安装即可。</p>
</li>
</ul>
<hr />
<hr />
<h1 id="2windows-10-64bit">2.Windows-10-64bit</h1>
<h2 id="21">2.1.基本工具</h2>
<h4 id="windowsconemu">（可选）Windows终端工具：ConEmu</h4>
<ul>
<li>下载地址：<a href="https://conemu.github.io/">https://conemu.github.io/</a></li>
<li>初始设置</li>
</ul>
<p><img alt="img" src="../res/figure/ConEmu-Init.png" title="初始设置" /></p>
<ul>
<li>打开设置界面，注册右键菜单</li>
</ul>
<p><img alt="img" src="../res/figure/ConEmu.png" title="ConEmu" /></p>
<p><img alt="img" src="../res/figure/ConEmu-Settings-Integration.png" title="注册ConEmu右键菜单" /></p>
<hr />
<h4 id="_2">工具链集合</h4>
<p>gcc、openocd、build-tools、emacs、busybox工具集合包，可从网盘下载：</p>
<ul>
<li>链接：<a href="https://pan.baidu.com/s/1WwSaEajt6JqgMOLOa8iPEQ">https://pan.baidu.com/s/1WwSaEajt6JqgMOLOa8iPEQ</a></li>
<li>提取码：xwos</li>
<li>文件：gnumcu-windows.7z</li>
</ul>
<p>解压到安装目录<strong>C:\app</strong>：</p>
<pre><code class="sh">C:\app
   └─ gnumcu
        ├── arm-none-eabi
        ├── bin
        ├── include
        ├── lib
        ├── libexec
        ├── scripts
        └── share
</code></pre>

<p>将<strong>C:\app\gnumcu\bin</strong>增加到环境变量Path中</p>
<p><img alt="img" src="../res/figure/Windows-Path.png" title="环境变量" /></p>
<p>重启系统使得环境变量生效，测试工具链</p>
<pre><code class="sh">arm-none-eabi-gcc -v
openocd -v
</code></pre>

<p><img alt="img" src="../res/figure/Toolchain-Test.png" title="工具链测试" /></p>
<h4 id="_3">工具链来源</h4>
<ul>
<li><a href="https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/">GNU Arm Embedded GCC</a></li>
<li><a href="https://github.com/xpack-dev-tools/openocd-xpack/releases/">OpenOCD</a></li>
<li><a href="https://github.com/gnu-mcu-eclipse/windows-build-tools/releases/">GNU MCU Eclipse Windows Build Tools</a></li>
<li><a href="https://mirror.bjtu.edu.cn/gnu/emacs/windows/emacs-26/emacs-26.3-x86_64-no-deps.zip">emacs</a><ul>
<li>用途：执行elisp脚本。</li>
</ul>
</li>
</ul>
<hr />
<h2 id="22stm32cubeide">2.2.STM32CubeIDE</h2>
<ul>
<li>优点：官方工具，有一个强大的SFR插件，可以在调试时很方便查看外设寄存器的值；</li>
<li>缺点：不支持DAPLink调试器，不过可以安装OpenOCD插件支持。</li>
</ul>
<h4 id="ide_1">安装IDE</h4>
<ul>
<li>到<a href="https://www.st.com/content/st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-ides/stm32cubeide.html">STM32CubeIDE官网</a>下载exe的安装文件按提示安装即可；</li>
</ul>
<h4 id="openocd_1">安装OpenOCD插件</h4>
<ul>
<li>打开菜单"Help &#x2013;&gt; Install New Software&#x2026;"；</li>
<li>点击"Add&#x2026;"，增加下面的仓库；</li>
</ul>
<pre><code class="sh">Name: Eclipse Embedded CDT Plug-ins
URL: https://download.eclipse.org/embed-cdt/updates/neon/
</code></pre>

<ul>
<li>等待刷新，选择安装<ul>
<li>"<strong>C/C++ OpenOCD Debugging</strong>"插件；</li>
<li>"<strong>C/C++ J-Link Debugging</strong>"插件；</li>
</ul>
</li>
</ul>
<hr />
<h2 id="23stm32cubemx">2.3.STM32CubeMX</h2>
<ul>
<li>
<p>下载STM32CubeMx的安装包，网站链接：<a href="https://www.st.com/en/development-tools/stm32cubemx.html">STM32CubeMX</a></p>
</li>
<li>
<p>解压后找到安装包 <strong>SetupSTM32CubeMX-x.y.z.exe</strong> ，双击按照提示安装即可。</p>
</li>
</ul>
<hr />
<h1 id="_4">附录</h1>
<ul>
<li>下一篇 <a href="../02-Project-Setup-Guide/">工程配置指南</a></li>
</ul></div>
            </div>
        </div>

        <footer class="col-md-12">
            <hr>
            <p>Documentation built with <a href="https://www.mkdocs.org/">MkDocs</a>.</p>
        </footer>
        <script>
            var base_url = "../../..",
                shortcuts = {"help": 191, "next": 78, "previous": 80, "search": 83};
        </script>
        <script src="../../../js/base.js" defer></script>
        <script src="../../../search/main.js" defer></script>

        <div class="modal" id="mkdocs_search_modal" tabindex="-1" role="dialog" aria-labelledby="searchModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="searchModalLabel">搜索</h4>
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
            </div>
            <div class="modal-body">
                <p>
                    在这里所有文档：
                </p>
                <form>
                    <div class="form-group">
                        <input type="search" class="form-control" placeholder="搜索..." id="mkdocs-search-query" title="Type search term here">
                    </div>
                </form>
                <div id="mkdocs-search-results"></div>
            </div>
            <div class="modal-footer">
            </div>
        </div>
    </div>
</div><div class="modal" id="mkdocs_keyboard_modal" tabindex="-1" role="dialog" aria-labelledby="keyboardModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="keyboardModalLabel">Keyboard Shortcuts</h4>
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
            </div>
            <div class="modal-body">
              <table class="table">
                <thead>
                  <tr>
                    <th style="width: 20%;">Keys</th>
                    <th>Action</th>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <td class="help shortcut"><kbd>?</kbd></td>
                    <td>Open this help</td>
                  </tr>
                  <tr>
                    <td class="next shortcut"><kbd>n</kbd></td>
                    <td>Next page</td>
                  </tr>
                  <tr>
                    <td class="prev shortcut"><kbd>p</kbd></td>
                    <td>Previous page</td>
                  </tr>
                  <tr>
                    <td class="search shortcut"><kbd>s</kbd></td>
                    <td>Search</td>
                  </tr>
                </tbody>
              </table>
            </div>
            <div class="modal-footer">
            </div>
        </div>
    </div>
</div>

    </body>
</html>
